"use strict";


var App = require('./App.js');

/**
 * if it's a RpcServer, it will connet to zk, get a server id,
 * then, it will connect to mq, create a queue if not exists, 
 * the queue in topic type:xxx, 
 * then the server is one of the consumers of the queue
 *
 * if a RpcClient, it will connect to zk ,get a client id, 
 * then it will create a connect to mq,
 * create a topic id:xxx, and it's the only consumer of this queue
 */
function RpcServer(path) {
	if (!this instanceof RpcServer) {
		return new RpcServer(path);
	}

	var server = require(path);
	__wrapServer(this, server);
}


module.exports = RpcServer;


function __wrapServer(rpcServer, server) {
	if (typeof server === 'function') {
		server = new server();
	}

	var slice = Array.prototype.slice;
	function handle() {
		var args = alice.apply(arguments);
		var m = args[0];
	}

	App(server.type, handle, function(err) {
		if (err) console.log(err);
		else console.log('%s ok', __type);
	});
}

// rpcClient.getBookById(arg,cb)
// => 



RpcServer.prototype.start = function() {

}